import React from 'react';
import base from '../../util/base';
import { Icon } from 'weaver-mobile';
import { Tools } from 'weaver-mobile';
import * as EmSDK from "../../util/emSDK";
const getLabel = Tools.getLabel;
export default class Main extends React.Component {


  getOperator(arr, str) {
    let operatorArr = arr;
    if( operatorArr && operatorArr.length > 0 && operatorArr.length > 10) {
      operatorArr = operatorArr.slice(0,10);
    }
    return (
      <React.Fragment>
        <span className='next-operator'>{getLabel(515204,'下一节点操作者:')} </span>
        {
          operatorArr && operatorArr.length != 0 && operatorArr.map( (item,index) => {
            let hasAgent = item.isbeAgent == 'true' ? true : false;
            if(hasAgent) { //有代理的情况
              if(index == 9) {
                return (<a  onClick={() => {window.openLink.openHrm(item.operatorid)}} 
                            className="operator">
                            {item.beagentname + '->' + item.operatorname  + '...'}
                        </a>)
              } else {
                return (<a onClick={() => {window.openLink.openHrm(item.operatorid)}} 
                            className="operator" >
                          {item.beagentname + '->' + item.operatorname}
                        </a>)
              }
            } else {
              if(index == 9) {
                return (<a onClick={() => {window.openLink.openHrm(item.operatorid)}} 
                          className='operator'> 
                          {item.operatorname + '...'}
                        </a>)
              } else {
                return (<a onClick={() => {window.openLink.openHrm(item.operatorid)}} 
                          className='operator'> 
                          {item.operatorname}
                        </a>)
              }
            }
          })
        }
         { operatorArr.length == 0 && <span style={{marginLeft: '5px'}}>{str}</span>}
    </React.Fragment>
    )
   
  }
  //跳转至流程图Tab 
  jumpWfMap() {
    let urlParams = base.wfGlobalStore.urlParams;
    base.smartGuessStore.openForecastFunc(true);
    base.smartGuessStore.clickSmartBtn();
    base.allStores.wfOperateStore.controllBottomBtnDisable(false);
    EmSDK.resetBottomBtn()//隐藏底部按钮
    window.historyRoute.push({
      pathname: "/req/picture",
      params: base.wfGlobalStore.queryParams,
    });

  }

  getInfo = () => {
    const { ensureSubmitInfo } = base.smartGuessStore;
    const  { isFree, openAutoForecast='0'} = base.wfGlobalStore.commonParam
    let canGetNextNode = false;
    if(ensureSubmitInfo.isSuccess) {
      canGetNextNode = true;
    }
    let str = ensureSubmitInfo.titlesuffix || ' ';
    while(str && str.indexOf('span') > -1) {
      str = str.replace('<span>', '').replace('</span>', ' ');
    } 
    let nextNodeStr = str;
    var dialogContent = (
      <div className={'ensure-submit-modal'}>
        <div className='content-box'>
          {
            canGetNextNode 
            ? <p className="next-node">{getLabel(515203,'下一节点：')} {nextNodeStr}</p>
            : <p>{getLabel(515207, '下一节点无法预知')}</p>
          }
          <p className='operator-text'>
            {
              canGetNextNode 
              && ensureSubmitInfo.operators 
              && ensureSubmitInfo.operators.length > 0  
              && this.getOperator(ensureSubmitInfo.operators)
            }
            {
              (canGetNextNode && !ensureSubmitInfo.operators)  
              || (canGetNextNode && ensureSubmitInfo.operators.length == 0) 
              && this.getOperator([], nextNodeStr)
            }
          </p>
          {
            isFree != '1' 
            && openAutoForecast == '1'
            && <a className={'forcast-link'} onClick={this.jumpWfMap.bind(this)}> 
              {getLabel(515205, '点击这里查看后续流转预测')}
              <Icon type="arrow-down-o" size={'xxs'} style={{transform: 'rotate(270deg)'}} />
            </a>
          }
        </div>  
      </div>
    )
    return dialogContent;
  }
  render() {
    let promptInfo = this.getInfo();
    return (
      <div>{promptInfo}</div>
    )
  }
}